<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:s="http://jboss.com/products/seam/taglib"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:a4j="http://richfaces.org/a4j"
      template="/layout/administration.xhtml">
      
      <ui:define name="head">

	  </ui:define>
    
    <ui:define name="title">
			<h3>Users</h3>
	</ui:define>
		
	<ui:define name="list">
            <h:outputText value="No user exists" rendered="#{empty userList.resultList}"/>

            <h:dataTable id="userList" var="user" value="#{userList.resultList}" rendered="#{not empty userList.resultList}">
                <h:column>
                    <f:facet name="header">Id</f:facet>
                    #{user.id}
                </h:column>
                <h:column>
                    <f:facet name="header">Nick name</f:facet>
                    #{user.nickName}
                </h:column>
                <h:column>
                    <f:facet name="header">Name</f:facet>
                    <s:link id="user" value="#{user.name}" propagation="none" view="/admin/users.xhtml">
                        <f:param name="userId" value="#{user.id}"/>
                    </s:link>
                </h:column>
                <h:column>
                    <f:facet name="header">Project</f:facet>
                    <s:link id="project" value="#{user.project.name}" propagation="none" view="/admin/projects.xhtml">
                        <f:param name="projectId" value="#{user.project.id}"/>
                    </s:link>
                </h:column>
                <h:column>
                    <f:facet name="header">Role</f:facet>
                    #{user.role}
                </h:column>
            </h:dataTable>
    </ui:define>
    <ui:define name="settings">
        <h:form id="userForm">	
	        	<h4>Add, modify or delete a user:</h4>
	        	<h:outputText value="Name: "/><br/>
	        	<h:inputText value="#{userHome.instance.name}" /><br/>
	        	<h:outputText value="Nick name: "/><br/>
	        	<h:inputText value="#{userHome.instance.nickName}" /><br/>
	        	<h:outputText value="Password: "/><br/>
	        	<h:inputSecret value="#{userHome.instance.password}" /><br/>
	        	<h:outputText value="Role: "/><br/>
	        	<h:selectOneMenu value="#{userHome.instance.role}">
	        		<f:selectItem itemValue="Administrator"/>
	        		<f:selectItem itemValue="Member"/>
	        	</h:selectOneMenu><br/>
	        	<h:outputText value="Project: "/><br/>
	        	<h:selectOneMenu id="project_list" value="#{userHome.instance.project}">
	        		<s:selectItems var="item" value="#{projectList.resultList}" label="#{item.name}" itemValue="#{item}" />
	        		<s:convertEntity />
	        	</h:selectOneMenu><br/>
	        	<div class="commandButtons">
		            <h:commandButton id="save"
		                          value="Create"
		                         action="#{userHome.persist}"
		                       rendered="#{!userHome.managed}"/>
		            <h:commandButton id="update"
		                          value="Save"
		                         action="#{userHome.update}"
		                       rendered="#{userHome.managed}"/>
		            <h:commandButton id="delete"
		                          value="Delete"
		                         action="#{userHome.remove}"
		                      immediate="true"
		                       rendered="#{userHome.managed}"/>
		            <s:button propagation="end"
		                               id="cancel"
		                            value="Cancel"
		                             view="/admin/users.xhtml"/>
	            </div>
	    </h:form>
	</ui:define>

</ui:composition>